export function makeUpJs(config) {

    // 获取方法
    let methodList = [];

    function extractFun(arr) {
        arr.forEach(item => {
            if (item.options && (item.options.dynamicFun || item.options.customFun)) {
                methodList.push({
                    dynamicFun: item.options.dynamicFun,
                    customFun: item.options.customFun,
                    type: item.type
                });
            }
            if (item.columns) {
                extractFun(item.columns);
            }
            if (item.list) {
                extractFun(item.list);
            }
        });
    }
    extractFun(config.list);
    methodList = methodList.filter(type => type.dynamicFun !== '');
    methodList = methodList.map(el => {
        return `${el.dynamicFun}() {${el.customFun}},`
    })

    const script = buildexport(
        config,
        methodList.join('\n'),
    )

    return script
}

// js整体拼接
function buildexport(conf, methods) {

    console.log('conf',conf);
    const rxbutton = conf.list

    // 获取类型
    function findTypes(obj) {
        let types = [];
        if (Array.isArray(obj)) {
            obj.forEach(item => {
                types = types.concat(findTypes(item));
            });
        } else if (typeof obj === 'object' && obj !== null) {
            for (let key in obj) {
                if (key === 'type') {
                    types.push(obj[key]);
                } else {
                    types = types.concat(findTypes(obj[key]));
                }
            }
        }
        return types;
    }
    let types = findTypes(rxbutton);

    types = types.filter(type => type !== 'primary' && type !== 'danger');
    types = [...new Set(types)];

    let modules = []
    let components = []

    types.map(item => {
        if(item == 'RxButton') {
            modules.push('import { RxButton } from "jpaas-common-lib"')
            components.push('RxButton,')
        }
    })

    console.log('modules',modules);

    const str = `export default {
        components: {
            ${components.join('\n')}
        },
        props: [],
        data () {
        return {
            
        }
        },
        computed: {},
        watch: {},
        created () {
        },
        mounted () {},
        methods: {
            ${methods}
        }
    }`
    return modules.join('\n') + str
  }
  